package com.shuoyue.ycgk.ui.estimate;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.Estimate;
import com.shuoyue.ycgk.entity.SourtInfo;
import com.shuoyue.ycgk.entity.Unit;
import com.shuoyue.ycgk.entity.UserTestPaper;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface SourtContract {
    interface View extends BaseView {
        void getSourtSuc(SourtInfo list);

        void getUnitSuc(Unit userTestPaper);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getUnitInfo(Integer evaId) {
            apply(model.getUnitInfo(evaId))
                    .subscribe(new ApiSubscriber<Optional<Unit>>(mView, this) {
                        @Override
                        public void onNext(Optional<Unit> listWithPageOptional) {
                            super.onNext(listWithPageOptional);
                            mView.getUnitSuc(listWithPageOptional.getIncludeNull());
                        }
                    });
        }

        public void getSourt(Integer evaId, int n, int type) {
            apply(model.getSourt(evaId, n, type))
                    .subscribe(new ApiSubscriber<Optional<SourtInfo>>(mView, this) {
                        @Override
                        public void onNext(Optional<SourtInfo> listWithPageOptional) {
                            super.onNext(listWithPageOptional);
                            mView.getSourtSuc(listWithPageOptional.getIncludeNull());
                        }
                    });
        }
    }

    class Model {
        Observable<BaseResult<SourtInfo>> getSourt(Integer evaId, int n, int type) {
            return RetrofitClient.getInstance().getApi().getSourt(evaId, n, type);
        }

        Observable<BaseResult<Unit>> getUnitInfo(Integer evaId) {
            return RetrofitClient.getInstance().getApi().getUnitInfo(evaId);
        }
    }
}
